package cn.alm.allinoneboot.utils;

import cn.alm.allinoneboot.entity.User;
import io.jsonwebtoken.*;

import java.util.Date;

public class JwtUtil {

    private static String secretKey = "abc123";

    public static String createToken(User user) {
        String username = user.getUsername();
        JwtBuilder jwtBuilder = Jwts.builder().setId(username).setSubject(username).setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS512, JwtUtil.secretKey);
        return jwtBuilder.compact();
    }

    public static Claims parseJwt(String token) {
        Claims claims = (Claims) Jwts.parser().setSigningKey(JwtUtil.secretKey).parse(token).getBody();
        return claims;
    }
}







